﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ProjectWebNhac.BUS;
using ProjectWebNhac.DTO;
using System.Data;


namespace ProjectWebNhac.GUI.User
{
    public partial class User : System.Web.UI.MasterPage
    {
        NguoiDungDTO objND = new NguoiDungDTO();
        AlbumBus abbus = new AlbumBus();
        NguoiDungBus ndbus = new NguoiDungBus();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["ThanhVien"] != null)
                {
                    Dalogin.Visible = true;
                    Chualogin.Visible = false;
                }
                else
                {
                    Dalogin.Visible = false;
                    Chualogin.Visible = true;
                }
                loadAlbumNew();
                
                Page.Form.DefaultButton = lnkLogin.UniqueID;
            }
        }


        private void loadAlbumNew()
        {
            reAlbumNew.DataSource = abbus.LayDanhSachAlbumMoi();
            reAlbumNew.DataBind();
        }

        protected void btnDongY_Click(object sender, EventArgs e)
        {
            objND.MatKhau = txtMatKhauDK.Text;
            objND.HoTen = txtHoTenDK.Text;
            objND.TaiKhoan = txtTenDangNhapDK.Text;
            objND.Email = txtEmailDK.Text;
            if (txtMatKhauDK.Text == txtXNMatKhauDK.Text)
                {
                    if (txtMaBaoVe.Text.Equals(Session["captcha"].ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        if (ndbus.RegisterUser(objND))
                        {
                            DataTable dt = ndbus.LoginUser(objND);
                            if (dt.Rows.Count > 0)
                            {
                                Response.Redirect("TrangChu.aspx");
                            }
                        }
                    }
                    else
                    {
                        lbThongBao.Text = "Vui lòng nhập đúng chuỗi xác nhận";
                    }
                }
            else
                lbThongBao.Text = "Vui lòng nhập đúng chuỗi xác nhận";
        }

        protected void lnkLogin_Click(object sender, EventArgs e)
        {
            objND.TaiKhoan = txtTenDangNhap.Text;
            objND.MatKhau = txtMatKhau.Text;
            DataTable dt= ndbus.LoginUser(objND);
            if (dt.Rows.Count > 0)
            {
                Response.Redirect("TrangChu.aspx");
            } 
        }

        protected void btnAccept_Click(object sender, EventArgs e)
        {
            Response.Redirect("TrangChu.aspx");
        }


        protected void btnLoggout_Click(object sender, EventArgs e)
        {
            Session["ThanhVien"] = null;
            Response.Redirect("TrangChu.aspx");
        }

        protected void btnSearch_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("TimKiem.aspx?keyword=" + txtSearch.Text);
        }

 

    }
}